package action;

import java.util.List;

import javax.persistence.criteria.Order;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import po.OrderWithUser;
import service.InviteService;

public class InviteAction extends ActionSupport{
	private List orders;
	private List info;
	private String type;
	private String course;
	private String sex;
	
	public List getOrders(){
		return orders;
	}
	public List getInfo() {
		return info;
	}
	
	public void setOrders(List order) {
		this.orders = order;
	}
	public void setInfo(List info) {
		this.info = info;
	}
	
	//这里要修改 直接通过orders来取
	public void change(String typeTemp,String courseTemp,String sexTemp) {
		switch(Integer.parseInt(typeTemp)) {
		case 1:
			type = "小学一年级";
			break;
		case 2:
			type = "小学二年级";
			break;
		case 3:
			type = "小学三年级";
			break;
		case 4:
			type = "小学四年级";
			break;
		case 5:
			type = "小学五年级";
			break;
		case 6:
			type = "小学六年级";
			break;
		case 7:
			type = "初中一年级";
			break;
		case 8:
			type = "初中二年级";
			break;
		case 9:
			type = "初中三年级";
			break;
		case 10:
			type = "高中一年级";
			break;
		case 11:
			type = "高中二年级";
			break;
		case 12:
			type = "高中三年级";
			break;
			
		}
		
		switch(Integer.parseInt(courseTemp)) {
		case 1:
			course = "语文";
			break;
		case 2:
			course = "数学";
			break;
		case 3:
			course = "英语";
			break;
		case 4:
			course = "化学";
			break;
		case 5:
			course = "物理";
			break;
		case 6:
			course = "英语";
			break;
		case 7:
			course = "美术";
			break;
		case 8:
			course = "生物";
			break;
		case 9:
			course = "地理";
			break;
		case 10:
			course = "政治";
			break;
		}
		
		switch(Integer.parseInt(sexTemp)) {
		case 1:
			sex = "男";
			break;
		case 2:
			sex = "女";
			break;
		}
	}
	public String select() {
		
		HttpServletRequest request = ServletActionContext.getRequest(); //得到quest对象
		//从三个选择框中获取信息
		String typeTemp = request.getParameter("type");
		
		String courseTemp = request.getParameter("course");
		String sexTemp = request.getParameter("sex");
		change(typeTemp,courseTemp,sexTemp);
		
		//System.out.println(type+" "+course+" "+sex);
		InviteService invite = new InviteService();
		if(invite.searchOrder(type, course, sex)) { //判断搜索
			
			orders = invite.getOrders(); //获得信息
		
			
			return "success";
			
		}
		else
			return "failed";
	}
	
	public String getAll() {
		InviteService invite = new InviteService();
		if(invite.getAllOrder()) { //判断搜索		
			orders = invite.getOrders(); //获得信息		
			return "success";		
		}
		else
			return "failed";
	}
}
